home *** CD-ROM | disk | FTP | other *** search
/ Macworld Expo - Develope…Central & Net Innovations / Developer Central and Net Innovators (MacWorld Expo) (January 1999).iso / Developer Central / Bowers Development / Demo AppMaker / Examples / PowerPlant / Everything / CModalText.cp < prev    next >
Encoding:
Text File  |  1998-10-11  |  9.0 KB  |  467 lines  |  [TEXT/CWIE]

  1. // CModalText.cp -- dialog methods
  2.  
  3. #include "CModalText.h"
  4.  
  5. #include <UEnvironment.h>
  6. #include <UReanimator.h>
  7. #include <URegistrar.h>
  8. #include <LStream.h>
  9. #include <LTabGroup.h>
  10. #include <LPushButton.h>
  11. #include <LAMPushButtonImp.h>
  12. #include <LGAPushButtonImp.h>
  13. #include <LEditText.h>
  14. #include <LAMEditTextImp.h>
  15. #include <LGAEditTextImp.h>
  16. #include <LScrollerView.h>
  17. #include <LScrollBar.h>
  18. #include <LAMTrackActionImp.h>
  19. #include <LStdScrollBarImp.h>
  20. #include <LTextEditView.h>
  21. #include <CDoubleEditText.h>
  22. #include <LClock.h>
  23. #include <LAMControlImp.h>
  24. #include <CTextUtils.h>
  25.  
  26. #include "DModalTextData.h"
  27. #include "EverythingCmds.h"
  28. #include <PP_Messages.h>
  29.  
  30. const MessageT    msgSmall    = 'Smal';
  31. const MessageT    msgX12345    = 'X145';
  32. const MessageT    msgX12345e6    = 'X126';
  33. const MessageT    msgPassword    = 'Pasd';
  34. const MessageT    msgDate    = 'Date';
  35. const MessageT    msgTime    = 'Time';
  36.  
  37. #define PPob_ModalTextID    211
  38. #define RidL_ModalTextID    211
  39.  
  40. Boolean        CModalText::sIsRegistered = false;
  41.  
  42. //----------
  43. CModalText*        CModalText::CreateModalText (
  44.     LCommander*        inSuperCommander,
  45.     CommandT        inCommand,
  46.     DModalTextData*        inData)
  47. {
  48.     if (!sIsRegistered) {
  49.         RegisterClass ();
  50.     }
  51.     CModalText*        dlog;
  52.     dlog = ((CModalText *)LWindow::CreateWindow(PPob_ModalTextID, inSuperCommander));
  53.     dlog->mCommand = inCommand;
  54.     dlog->SetFromData (inData);
  55.  
  56.     return dlog;
  57. }
  58.  
  59. //----------
  60. #define    RegisterClasses(AbstractClass,AMImpClass,GAImpClass)    \
  61.     RegisterClass_(AbstractClass);    \
  62.     if (useAppearance) {    \
  63.         RegisterClassID_(AMImpClass, AbstractClass::imp_class_ID);    \
  64.     } else {    \
  65.         RegisterClassID_(GAImpClass, AbstractClass::imp_class_ID);    \
  66.     }
  67.  
  68. //----------
  69. void    CModalText::RegisterClass ()
  70. {
  71.     Boolean        useAppearance = UEnvironment::HasFeature (env_HasAppearance);
  72.  
  73.     RegisterClass_(CModalText);
  74.  
  75.     // register the pane classes we use
  76.     RegisterClasses (LPushButton, LAMPushButtonImp, LGAPushButtonImp);
  77.     RegisterClasses (LEditText, LAMEditTextImp, LGAEditTextImp);
  78.     RegisterClass_(LScrollerView);
  79.     RegisterClasses (LScrollBar, LAMTrackActionImp, LStdScrollBarImp);
  80.     RegisterClass_(LTextEditView);
  81.     RegisterClasses (CDoubleEditText, LAMEditTextImp, LGAEditTextImp);
  82.     RegisterClasses (LClock, LAMControlImp, LAMControlImp);
  83.  
  84.     sIsRegistered = true;
  85. }
  86.  
  87. //----------
  88. CModalText::CModalText (
  89.     LStream*    inStream)
  90.     : LGADialog (inStream)
  91. {
  92.     mData = nil;
  93. }
  94.  
  95. //----------
  96. CModalText::~CModalText()
  97. {
  98.     delete mData;
  99. }
  100.  
  101. //----------
  102. //    This member function gets called once the containment hierarchy that contains
  103. //    this pane has been built. It gives us a chance to get data members for
  104. //    interesting subviews, and to do other operations now that our subviews exist.
  105. void    CModalText::FinishCreateSelf()
  106. {
  107.     LGADialog::FinishCreateSelf();
  108.  
  109.     mOKButton = (LPushButton*) FindPaneByID ('OK  ');
  110.  
  111.     mSmallField = (LEditText*) FindPaneByID ('Smal');
  112.     mSmallField->AddListener (this);
  113.  
  114.     mLargeField = (LTextEditView*) FindPaneByID ('Lare');
  115.  
  116.     mX12345Field = (LEditText*) FindPaneByID ('X145');
  117.     mX12345Field->AddListener (this);
  118.  
  119.     mX12345e6Field = (CDoubleEditText*) FindPaneByID ('X126');
  120.     mX12345e6Field->AddListener (this);
  121.  
  122.     mPasswordField = (LEditText*) FindPaneByID ('Pasd');
  123.     mPasswordField->AddListener (this);
  124.  
  125.     mDateField = (LClock*) FindPaneByID ('Date');
  126.     mDateField->AddListener (this);
  127.  
  128.     mTimeField = (LClock*) FindPaneByID ('Time');
  129.     mTimeField->AddListener (this);
  130.  
  131.     mStyledField = (LTextEditView*) FindPaneByID ('Styd');
  132.  
  133.  
  134.     LTabGroup*        tabGroup = new LTabGroup(this);
  135.     mSmallField->SetSuperCommander(tabGroup);    // becomes the active field
  136.     mLargeField->SetSuperCommander(tabGroup);
  137.     mX12345Field->SetSuperCommander(tabGroup);
  138.     mX12345e6Field->SetSuperCommander(tabGroup);
  139.     mPasswordField->SetSuperCommander(tabGroup);
  140.     mDateField->SetSuperCommander(tabGroup);
  141.     mTimeField->SetSuperCommander(tabGroup);
  142.     mStyledField->SetSuperCommander(tabGroup);
  143.  
  144.     UReanimator::LinkListenerToControls(this, this, RidL_ModalTextID);
  145.         // the purpose is to "connect" self to whatever controls
  146.         // that we want to "listen" to
  147.  
  148. // any additional initialization for your dialog:
  149.  
  150. }
  151.  
  152. //----------
  153. void    CModalText::SetFromData (
  154.     DModalTextData*        inData)
  155. {
  156.     mData = inData;
  157.     mData->AddListener (this);
  158.  
  159.     CTextUtils::SetText (mSmallField, mData->GetSmall2 ());
  160.     CTextUtils::SetText (mLargeField, mData->GetLarge2 ());
  161.     mX12345Field->SetValue (mData->GetX12346 ());
  162.     mX12345e6Field->SetDValue (mData->GetX12345e7 ());
  163.     CTextUtils::SetText (mPasswordField, mData->GetPassword2 ());
  164.     {
  165.         LongDateRec        dateTime = mData->GetDate2 ();
  166.         mDateField->SetLongDate (dateTime);
  167.     }
  168.     {
  169.         LongDateRec        dateTime = mData->GetTime2 ();
  170.         mTimeField->SetLongDate (dateTime);
  171.     }
  172.     CTextUtils::SetText (mStyledField, mData->GetStyled2 ());
  173. }
  174.  
  175. //----------
  176. DModalTextData*        CModalText::GetData ()
  177. {
  178.     mData->SetLarge2 ((CharsHandle)(mLargeField->GetTextHandle ()));
  179.     mData->SetStyled2 ((CharsHandle)(mStyledField->GetTextHandle ()));
  180.  
  181.     return mData;
  182. }
  183.  
  184. //----------
  185. void    CModalText::DataChanged (
  186.     long        inDataID)
  187. {
  188.     StopListening ();
  189.  
  190.     if (inDataID == idSmall2) {
  191.         if (!mSmallField->IsTarget ()) {
  192.             CTextUtils::SetText (mSmallField, mData->GetSmall2 ());
  193.         }
  194.     }
  195.     if (inDataID == idLarge2) {
  196.         CTextUtils::SetText (mLargeField, mData->GetLarge2 ());
  197.     }
  198.     if (inDataID == idX12346) {
  199.         if (!mX12345Field->IsTarget ()) {
  200.             mX12345Field->SetValue (mData->GetX12346 ());
  201.         }
  202.     }
  203.     if (inDataID == idX12345e7) {
  204.         if (!mX12345e6Field->IsTarget ()) {
  205.             mX12345e6Field->SetDValue (mData->GetX12345e7 ());
  206.         }
  207.     }
  208.     if (inDataID == idPassword2) {
  209.         if (!mPasswordField->IsTarget ()) {
  210.             CTextUtils::SetText (mPasswordField, mData->GetPassword2 ());
  211.         }
  212.     }
  213.     if (inDataID == idDate2) {
  214.         LongDateRec        dateTime = mData->GetDate2 ();
  215.         mDateField->SetLongDate (dateTime);
  216.     }
  217.     if (inDataID == idTime2) {
  218.         LongDateRec        dateTime = mData->GetTime2 ();
  219.         mTimeField->SetLongDate (dateTime);
  220.     }
  221.     if (inDataID == idStyled2) {
  222.         CTextUtils::SetText (mStyledField, mData->GetStyled2 ());
  223.     }
  224.  
  225.     StartListening ();
  226. }
  227.  
  228. //----------
  229. void    CModalText::ListenToMessage (
  230.     MessageT    inMessage,
  231.     void        *ioParam)
  232. {
  233.     switch (inMessage) {
  234.     case msg_OK:
  235.             GetSuperCommander()->ProcessCommand(-mCommand, this);
  236.         break;
  237.  
  238.     case msg_Cancel:
  239.             DoClose();
  240.         break;
  241.  
  242.     case msgDataChanged:
  243.             DataChanged ((long)ioParam);
  244.         break;
  245.  
  246.     case msgSmall:
  247.         {
  248.             Str255        string;
  249.  
  250.             mSmallField->GetDescriptor (string);
  251.             mData->SetSmall2 (string);
  252.         }
  253.         break;
  254.  
  255.     case msgX12345:
  256.             mData->SetX12346 (mX12345Field->GetValue ());
  257.         break;
  258.  
  259.     case msgX12345e6:
  260.             mData->SetX12345e7 (mX12345e6Field->GetDValue ());
  261.         break;
  262.  
  263.     case msgPassword:
  264.         {
  265.             Str255        string;
  266.  
  267.             mPasswordField->GetDescriptor (string);
  268.             mData->SetPassword2 (string);
  269.         }
  270.         break;
  271.  
  272.     case msgDate:
  273.         {
  274.             LongDateRec        dateTime;
  275.  
  276.             mDateField->GetLongDate (dateTime);
  277.             mData->SetDate2 (dateTime);
  278.         }
  279.         break;
  280.  
  281.     case msgTime:
  282.         {
  283.             LongDateRec        dateTime;
  284.  
  285.             mTimeField->GetLongDate (dateTime);
  286.             mData->SetTime2 (dateTime);
  287.         }
  288.         break;
  289.  
  290.  
  291.     default:
  292.           ; // do something
  293.         break;
  294.     }
  295. }
  296.  
  297. //----------
  298. Boolean        CModalText::ObeyCommand (
  299.     CommandT    inCommand,
  300.     void*        ioParam)
  301. {
  302.     Boolean        cmdHandled = true;
  303.  
  304.     if (inCommand < 0) {
  305.         // modal dialog has finished
  306.  
  307.         switch (-inCommand) {
  308.         }
  309.  
  310.     } else {
  311.         switch (inCommand) {
  312.  
  313.         default:
  314.                 cmdHandled = LGADialog::ObeyCommand(inCommand, ioParam);
  315.             break;
  316.         }
  317.     }
  318.  
  319.     return cmdHandled;
  320. }
  321.  
  322. //----------
  323. void    CModalText::FindCommandStatus (
  324.     CommandT    inCommand,
  325.     Boolean        &outEnabled,
  326.     Boolean        &outUsesMark,
  327.     Char16        &outMark,
  328.     Str255        outName)
  329. {
  330.     outUsesMark = false;
  331.  
  332.     switch (inCommand) {
  333.  
  334.     // +++ Add cases here for the commands you handle
  335.  
  336.     default:
  337.             LGADialog::FindCommandStatus(inCommand, outEnabled,
  338.                                             outUsesMark, outMark, outName);
  339.         break;
  340.     }
  341. }
  342.  
  343. // following functions will be obsoleted
  344. // retained only for backwards compatibility
  345. //----------
  346. void
  347. CModalText::GetSmallFieldString (
  348.     Str255        str)
  349. {
  350.     mSmallField->GetDescriptor (str);
  351. }
  352.  
  353. //----------
  354. void
  355. CModalText::SetSmallFieldString (
  356.     ConstStr255Param        str)
  357. {
  358.     mSmallField->SetDescriptor (str);
  359. }
  360.  
  361.     /*
  362.     //----------
  363.     Ptr
  364.     CModalText::GetLargeFieldText ()
  365.     {
  366.     }
  367.  
  368.     //----------
  369.     void
  370.     CModalText::SetLargeFieldText (
  371.         Ptr        str)
  372.     {
  373.     }
  374.     */
  375.  
  376. //----------
  377. Int32
  378. CModalText::GetX12345FieldValue ()
  379. {
  380.     return mX12345Field->GetValue ();
  381. }
  382.  
  383. //----------
  384. void
  385. CModalText::SetX12345FieldValue (
  386.     Int32        inNum)
  387. {
  388.     mX12345Field->SetValue (inNum);
  389. }
  390.  
  391. //----------
  392. double
  393. CModalText::GetX12345e6FieldValue ()
  394. {
  395.     return mX12345e6Field->GetDValue ();
  396. }
  397.  
  398. //----------
  399. void
  400. CModalText::SetX12345e6FieldValue (
  401.     double        inNum)
  402. {
  403.     mX12345e6Field->SetDValue (inNum);
  404. }
  405.  
  406. //----------
  407. void
  408. CModalText::GetPasswordFieldString (
  409.     Str255        str)
  410. {
  411.     mPasswordField->GetDescriptor (str);
  412. }
  413.  
  414. //----------
  415. void
  416. CModalText::SetPasswordFieldString (
  417.     ConstStr255Param        str)
  418. {
  419.     mPasswordField->SetDescriptor (str);
  420. }
  421.  
  422.     /*
  423.     //----------
  424.     Date
  425.     CModalText::GetDateFieldDate ()
  426.     {
  427.     }
  428.  
  429.     //----------
  430.     void
  431.     CModalText::SetDateFieldDate (
  432.         Date        str)
  433.     {
  434.     }
  435.     */
  436.  
  437.     /*
  438.     //----------
  439.     Date
  440.     CModalText::GetTimeFieldDate ()
  441.     {
  442.     }
  443.  
  444.     //----------
  445.     void
  446.     CModalText::SetTimeFieldDate (
  447.         Date        str)
  448.     {
  449.     }
  450.     */
  451.  
  452.     /*
  453.     //----------
  454.     Ptr
  455.     CModalText::GetStyledFieldText ()
  456.     {
  457.     }
  458.  
  459.     //----------
  460.     void
  461.     CModalText::SetStyledFieldText (
  462.         Ptr        str)
  463.     {
  464.     }
  465.     */
  466.  
  467.